package com.emep.changzhi.analyse.service.information;


import com.emep.changzhi.analyse.entity.information.SysSendeRule;
import com.emep.changzhi.analyse.entity.information.SysWarningRecord;
import com.emep.changzhi.analyse.repository.information.SysSendRuleRepository;
import com.emep.changzhi.analyse.repository.information.SysWarningRecordRepository;
import com.emep.changzhi.analyse.utils.MapUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

@Service
@Slf4j
public class SysWarningRecordService {

    @Autowired
    SysWarningRecordRepository repository;


    public SysWarningRecord add(Map<String, Object> payload) {

        SysWarningRecord sysWarningRecord = null;
        try {
            SysWarningRecord sysWarningRecord1 = (SysWarningRecord) MapUtils.convertMap(SysWarningRecord.class,payload);
            sysWarningRecord = repository.save(sysWarningRecord1);
        }catch (Exception e){
            log.error(e.getLocalizedMessage());
        }
        return sysWarningRecord;
    }

    public List<SysWarningRecord> getList() {

        List<SysWarningRecord> sysWarningRecords = null;
        try {
            sysWarningRecords =  repository.findAll();
        }catch (Exception e){
            log.error(e.getLocalizedMessage());
        }
        return sysWarningRecords;
    }




    public boolean delete(String id) {

        Boolean result = false;
        try {
            repository.deleteById(id);
            result =true;
        }catch (Exception e){
            log.error(e.getLocalizedMessage());
        }
        return result;

    }

}
